package com.sky.controller.User;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.HistoryService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user/order")
@Slf4j
@Api(tags = "历史订单查询")
public class HistoryOrderController {
    @Autowired
    private HistoryService historyService;

    @GetMapping("/historyOrders")
    @ApiOperation("查询历史订单")
    public Result<PageResult > histlist(OrdersPageQueryDTO ordersPageQueryDTO){
       PageResult p = historyService.historylist(ordersPageQueryDTO);
        return Result.success(p);
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询详情")
    public Result<OrderVO> list(@PathVariable long id){
            OrderVO orderVo =historyService.list(id);
            return Result.success(orderVo);
    }

    @PutMapping("cancel/{id}")
    @ApiOperation("根据id取消订单")
    public Result cancel(@PathVariable long id){
            historyService.cancel(id);
            return Result.success();
    }

    @PostMapping("repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable long id ){
        historyService.reprtitiong(id);
        return Result.success();
    }
}
